package org.jeecg.modules.data;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.CommonUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Objects;

@Slf4j
public class Common {
    /**
     * 挂号公众号授权地址：拼接
     *
     * @param url
     * @return
     */
    public static String operateUrl(String url) {
        String redirect = null;
        redirect = "https://zzt.weixin.dyzh120.com/doctors?token=";
        log.info("Common:" + redirect);
        return "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx5efe1f7c4a041b41&redirect_uri=https://zzt.weixin.api.dyzh120.com/auth?url=" + redirect + "&response_type=code&scope=snsapi_userinfo&state=DEFAULT&connect_redirect=1";
    }

    /**
     * 挂号公众号授权地址：拼接
     *
     * @param url
     * @return
     */
    public static String operateUrlToken(String url, String token) {
        String redirect = null;
        if (Objects.isNull(url)) {
            redirect = "https://zzt.weixin.dyzh120.com/doctors?token=";
        } else {
            redirect = "https://zzt.weixin.dyzh120.com/" + url + "?token=";  //授权后要跳到的地址
        }
        log.info("Common:" + redirect);
        return "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx4f53ddd052e1798c&redirect_uri=https://zzt.weixin.api.dyzh120.com/auth?url=" + redirect + "&response_type=code&scope=snsapi_userinfo&state=DEFAULT&connect_redirect=1";
    }

    /**
     * 日期字符串转周几
     *
     * @param dateStr
     * @return
     */
    public static String dateToWeek(String dateStr) throws ParseException {
//        Date date = StrToDate(dateStr);
        Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateStr + " 12:12:12");
        String[] weekDays = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
        Calendar cal = Calendar.getInstance();
        try {
            cal.setTime(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //一周的第几天
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (w < 0)
            w = 0;

        return weekDays[w];
    }


    /**
     * 日期转换成字符串
     *
     * @param date
     * @return str
     */
    public static String DateToStr(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String str = format.format(date);
        return str;
    }

    /**
     * 字符串转换成日期
     *
     * @param str
     * @return date
     */
    public static Date StrToDate(String str) {

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;
        try {
            date = format.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}
